package com.leather.question.vo;

import com.leather.common.entity.Answer;
import com.leather.common.result.CodeMsg;
import com.leather.common.result.Result;
import com.leather.common.toolkits.DateKit;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

@Data
public class AnswerAddVo implements Serializable {

    private Integer userId;

    private Integer questionId;

    private String content;


    public Result validate(){
        if(StringUtils.isBlank(content)) {
            return Result.error(CodeMsg.EMPTY_ANSWER_CONTENT);
        }
        if(userId==null||userId<=0) {
            return Result.error(CodeMsg.ERROR_USER_ID);
        }
        if(questionId==null||questionId<=0) {
            return Result.error(CodeMsg.ERROR_QUESTION_ID);
        }
        return Result.success(transfer());
    }


    public Answer transfer(){
        Answer answer = new Answer();
        answer.setId(0);
        answer.setUserId(userId);
        answer.setQuestionId(questionId);
        answer.setContent(content);
        answer.setCreateTime(DateKit.now());
        answer.setFlag(0);
        return answer;
    }
}
